<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-item label="供应商">
              <j-search-select-tag v-model="queryParam.supplierId" :async="true" dict="bas_supplier,name,id"
                placeholder="请选择" />
            </a-form-item>
          </a-col>
          <a-col :xl="5" :lg="7" :md="8" :sm="24">
            <a-form-model-item label="产品" :labelCol="labelCol" prop="productId">
              <j-search-select-tag v-model="queryParam.productId" :async="true" dict="bas_product,name,id"
                placeholder="请选择" />
            </a-form-model-item>
          </a-col>
          <template v-if="toggleSearchStatus">

          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button type="link" @click="handleAdd" icon="plus">新增</a-button>
      <!-- <a-button type="link" icon="download" @click="handleExportXls('产品订单')">导出</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"
        @change="handleImportExcel">
        <a-button type="link" icon="import">导入</a-button>
      </a-upload> -->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">删除</a-menu-item>
        </a-menu>
        <a-button type="link" style="margin-left: 8px">批量操作<a-icon type="down" /></a-button>
      </a-dropdown>
      <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
        selectedRowKeys.length
      }}</a>项
      <a v-if="selectedRowKeys.length > 0" style="margin-left: 12px" @click="onClearSelected">清空</a>

      <table-columns-setter v-model="columns" style="float: right;" />
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table ref="table" size="middle" bordered rowKey="id" :scroll="{ x: true }" :columns="columns"
        :dataSource="dataSource" :pagination="ipagination" :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" class="j-table-force-nowrap"
        :components="drag(columns)" @change="handleTableChange">

        <a slot="supplierId_dictText" @click="prodfinishcheckHandleDetail(record)" slot-scope="text, record">{{ text
          }}</a>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <prodfinishcheck-modal ref="modalForm" @ok="modalFormOk" />
  </a-card>
</template>

<script>

import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import prodfinishcheckModal from './modules/prodfinishcheckModal'
import TableColumnsSetter from '../common/components/TableColumnsSetter'
import { ListMixin } from '../common/mixins/ListMixin'
import XEUtils from "xe-utils";
// import {OrderListMixin} from '../common/mixins/OrderListMixin'
export default {
  name: "prodfinishcheckList",
  mixins: [JeecgListMixin, ListMixin],
  components: { TableColumnsSetter, prodfinishcheckModal },

  data() {
    return {
      description: '成品盘库',
      queryParam: {
        supplierId: '',
        productId: '',
        checkDate: '',
        type: '',
        checkUser: ''
      },

      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          fixed: 'left',
          width: 40,
          align: "center",
          customRender: (t, r, index) => parseInt(index) + 1
        },
        {
          title: '供应商',
          fixed: 'left',
          width: 160,
          align: "center",
          dataIndex: 'supplierId_dictText',
          scopedSlots: { customRender: 'supplierId_dictText' },
          sorter: true
        },
        {
          title: '产品',
          width: 160,
          align: "center",
          dataIndex: 'productId_dictText',
        },
        {
          title: '盘库日期',
          align: "center",
          dataIndex: 'checkDate',
          width: 260,
          customRender: t => !t ? "" : (t.length > 10 ? t.substr(0, 10) : t),
        },
        {
          title: '数量',
          width: 160,
          align: "center",
          dataIndex: 'qty',
          sorter: true
        },
        {
          title: '类别',
          width: 160,
          align: "center",
          dataIndex: 'type',
        },
        {
          title: '盘库人',
          width: 160,
          align: "center",
          dataIndex: 'checkUser',
          sorter: true
        },
        {
          title: '创建人',
          align: "center",
          width: 160,
          dataIndex: 'createBy',
          ellipsis: true,
        },
        {
          title: '创建时间',
          align: "center",
          dataIndex: 'createTime',
          width: 260,
          customRender: t => !t ? "" : (t.length > 10 ? t.substr(0, 10) : t),
        },

        {
          title: '更新人',
          width: 160,
          align: "center",
          dataIndex: 'updateBy'
        },
        {
          title: '更新时间',
          align: "center",
          dataIndex: 'updateTime',
          customRender: t => !t ? "" : (t.length > 10 ? t.substr(0, 10) : t),
        },
        {
          title: '操作',
          dataIndex: 'action',
          fixed: 'right',
          width: 120,
          align: "center",
          scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action'
          },
        }
      ],
      url: {
        list: "/wr/productStockCheck/list",
        delete: "/wr/productStockCheck/delete",
        deleteBatch: "/wr/productStockCheck/deleteBatch",
        exportXlsUrl: "/wr/productStockCheck/exportXls",
        importExcelUrl: "/wr/productStockCheck/importExcel",
      },
      dictOptions: {},
    }
  },

  methods: {
    initDictConfig() { },

    // 正确设置模态框action的新增方法
    handleAdd() {
      this.$refs.modalForm.action = 'add';
      this.$refs.modalForm.title = '新增';
      this.$refs.modalForm.add();
    },

    // 编辑方法 - 直接传递record数据
    handleEdit(record) {
      // 直接打开模态框并传递record，不调用mixin方法
      this.$refs.modalForm.visible = true;
      this.$refs.modalForm.action = 'edit';
      this.$refs.modalForm.title = '编辑';
      this.$refs.modalForm.disabled = false; // 编辑时不禁用表单
      // 直接传递record到表单组件
      this.$nextTick(() => {
        if (this.$refs.modalForm.$refs.realForm) {
          this.$refs.modalForm.$refs.realForm.setFormData(record);
        }
      });
    },

    // 查看方法
    handleDetail(record) {
      this.$refs.modalForm.action = 'detail';
      this.$refs.modalForm.title = '查看';
      this.$refs.modalForm.disabled = true;
      this.$refs.modalForm.edit(record);
    },

    // 成品盘库查看详情方法（与其他页面不重复）
    prodfinishcheckHandleDetail(record) {
      // 直接打开模态框并传递record，不调用mixin方法
      this.$refs.modalForm.visible = true;
      this.$refs.modalForm.action = 'detail';
      this.$refs.modalForm.title = '详情';
      this.$refs.modalForm.disabled = true;
      // 直接传递record到表单组件
      this.$nextTick(() => {
        if (this.$refs.modalForm.$refs.realForm) {
          this.$refs.modalForm.$refs.realForm.setFormData(record);
        }
      });
    }
  }

}
</script>

<style lang="less" scoped>
@import '~@assets/less/common.less';
@import '../common/less/List.less';
</style>
